package com.rental.common.exception;

import com.rental.common.result.AjaxResult;
import com.rental.common.result.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ProjectExceptionHandler {


    @ExceptionHandler(ProjectException.class)
    public AjaxResult error(ProjectException e) {
        log.info("发生自定义异常");
        e.printStackTrace();
        return AjaxResult.build(e.getCode(), e.getMessage(), null);
    }

    @ExceptionHandler(Exception.class)
    public AjaxResult error(Exception e) {
        log.info("程序发生异常");
        e.printStackTrace();
        return AjaxResult.build(e.getMessage(), ResultCodeEnum.ERROR);
    }


}
